<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居公司分类配置属性控制器($$)*/

!defined('Q_PATH') && exit;

class JiajucompanyclassController extends AController{

	public function filter_(&$arrMap){
		/*$arrMap['A.jiajucompany_fullname']=array('like','%'.Q::G('jiajucompany_fullname').'%');
		$arrMap['A.jiajucompany_shortname']=array('like','%'.Q::G('jiajucompany_shortname').'%');

		$nJiajucompanyIsavip=Q::G('jiajucompany_isavip');
		$nJiajucompanyIsfvip=Q::G('jiajucompany_isfvip');
		if($nJiajucompanyIsavip!==null && $nJiajucompanyIsavip!=''){
			$arrMap['A.jiajucompany_isavip']=$nJiajucompanyIsavip;
		}
		if($nJiajucompanyIsfvip!==null && $nJiajucompanyIsfvip!=''){
			$arrMap['A.jiajucompany_isfvip']=$nJiajucompanyIsfvip;
		}

		// 时间设置
		$this->getTime_('A.create_dateline',$arrMap);
		*/
		
		$nJiajucompanyclassParentid=Q::G('jiajucompanyclass_parentid');
		if($nJiajucompanyclassParentid!==null && $nJiajucompanyclassParentid!=''){
			$arrMap['A.jiajucompanyclass_parentid']=$nJiajucompanyclassParentid;
		}
	}

	public function index($sModel=null,$bDisplay=true){
		// 列表默认排序
		if(!isset($_GET['sort_'])){
			C::urlGo(Admin_Extend::base(array('controller'=>'jiajucompanyclass','sort_'=>'asc')));
		}
		
		// 首页列表
		parent::index('jiajucompanyclass',false);
		$this->bAdd_();
		$this->display(Admin_Extend::template('jiaju','jiajucompanyclass/index'));
	}

	public function add(){
		$this->bAdd_();
		$this->display(Admin_Extend::template('jiaju','jiajucompanyclass/add'));
	}
	
	public function bAdd_(){
		$oJiajucompanyclass=Q::instance('JiajucompanyclassModel');
		$this->assign('arrParentclass',$oJiajucompanyclass->getClass(0));
	}

	public function edit($sMode=null,$nId=null,$bDidplay=true){
		$nId=intval(Q::G('value','G'));
		$this->bEdit_();
		parent::edit('jiajucompanyclass',$nId,false);
		$this->display(Admin_Extend::template('jiaju','jiajucompanyclass/add'));
	}

	public function bEdit_(){
		$nId=Q::G('value');
		if($this->is_system_class($nId)){
			$this->E(Q::L('顶级分类无法编辑','__APPJIAJU_COMMON_LANG__@Controller'));
		}
		
		$this->bAdd_();
	}

	public function insert($sModel=null,$nId=null){
		$nId=Q::G('value');
		parent::insert('jiajucompanyclass',$nId);
	}


	public function update($sModel=null,$nId=null){
		$nId=Q::G('value');
		parent::update('jiajucompanyclass',$nId);
	}

	public function check_name(){
		$sJiajucompanyclassName=trim(Q::G('jiajucompanyclass_name'));
		$nId=intval(Q::G('value'));

		if(!$sJiajucompanyclassName){
			exit('false');
		}

		// 查询条件
		$arrWhere=array();
		$arrWhere['jiajucompanyclass_name']=$sJiajucompanyclassName;
		if($nId){
			$arrWhere['jiajucompanyclass_id']=array('neq',$nId);
		}

		$oJiajucompanyclass=JiajucompanyclassModel::F()->where($arrWhere)->setColumns('jiajucompanyclass_id')->getOne();
		if(empty($oJiajucompanyclass['jiajucompanyclass_id'])){
			exit('true');
		}else{
			exit('false');
		}
	}

	public function foreverdelete_deep($sModel=null,$sId=null){
		$sId=Q::G('value');
		$this->bForeverdelete_deep_();
		parent::foreverdelete_deep('jiajucompanyclass',$sId);
	}

	public function foreverdelete($sModel=null,$sId=null,$bApp=false){
		$sId=Q::G('value');
		$this->bForeverdelete_();
		parent::foreverdelete('jiajucompanyclass',$sId,true);
	}

	public function forbid($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::forbid('jiajucompanyclass',$nId,true);
	}

	public function resume($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::resume('jiajucompanyclass',$nId,true);
	}

	public function clear_recycle($sModel=null,$sField='status'){
		parent::clear_recycle('jiajucompanyclass',$sField);
	}

	public function bForeverdelete_deep_(){
		$this->bForeverdelete_();
	}

	public function bForeverdelete_(){
		$sId=Q::G('value','G');
		$arrIds=explode(',',$sId);
		foreach($arrIds as $nId){
			if($this->is_system_class($nId)){
				$this->E(Q::L('顶级分类无法删除','__APPJIAJU_COMMON_LANG__@Controller'));
			}
		}
	}

	public function is_system_class($arrValue){
		if(is_string($arrValue)){
			$arrValue=JiajucompanyclassModel::F('jiajucompanyclass_id=?',$arrValue)->getOne();
		}

		if($arrValue['jiajucompanyclass_parentid']==0){
			return true;
		}else{
			return false;
		}
	}

}
